//
//  LJJBuyCarTableViewCell.m
//  shopTest
//
//  Created by 梁佳佳 on 2016/11/22.
//  Copyright © 2016年 梁佳佳. All rights reserved.
//

#import "LJJBuyCarTableViewCell.h"

@interface LJJBuyCarTableViewCell ()

@property (strong, nonatomic) UILabel *titleLabel;    /** 标题 **/
@property (strong, nonatomic) UIImageView *iconImageView;    /** 商品图片 **/
@property (strong, nonatomic) UIImageView *backImageView;    /** 背景 **/
@property (strong, nonatomic) UILabel *goodsNumLabel;    /** 商品个数 **/
@property (strong, nonatomic) UILabel *priceLabel;    /** 价格 **/

@end

@implementation LJJBuyCarTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addSubview:self.titleLabel];
        [self addSubview:self.priceLabel];
        [self addSubview:self.goodsNumLabel];
        [self addSubview:self.isSelectButton];
        [self addSubview:self.addButton];
        [self addSubview:self.subButton];
        [self addSubview:self.iconImageView];
        [self addSubview:self.backImageView];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    __weak typeof(self) weakSelf = self;
    [_isSelectButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(21, 21));
        make.left.equalTo(weakSelf.mas_left).offset(15);
        make.centerY.equalTo(weakSelf.mas_centerY);
    }];
    [_iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(53, 53));
        make.left.equalTo(weakSelf.isSelectButton.mas_right).offset(8);
        make.centerY.equalTo(weakSelf.mas_centerY);
    }];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@13);
        make.left.equalTo(weakSelf.iconImageView.mas_right).offset(18);
        make.right.equalTo(weakSelf.mas_right).offset(-20);
        make.top.equalTo(weakSelf.iconImageView.mas_top);
    }];
    [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@13);
        make.left.equalTo(weakSelf.iconImageView.mas_right).offset(18);
        make.right.equalTo(weakSelf.backImageView.mas_right).offset(-20);
        make.bottom.equalTo(weakSelf.iconImageView.mas_bottom).offset(-7);
    }];
    [_backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(85, 25));
        make.bottom.equalTo(weakSelf.mas_bottom).offset(-15);
        make.right.equalTo(weakSelf.mas_right).offset(-17);
    }];
    [_subButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(25, 25));
        make.left.top.equalTo(weakSelf.backImageView);
    }];
    [_addButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(25, 25));
        make.right.top.equalTo(weakSelf.backImageView);
    }];
    [_goodsNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(weakSelf.backImageView);
        make.width.equalTo(@35);
        make.centerX.equalTo(weakSelf.backImageView.mas_centerX);
    }];
}
- (void)setBuyCarModel:(LJJBuyCarModel *)buyCarModel
{
    _buyCarModel = buyCarModel;
    [_iconImageView sd_setImageWithURL:[NSURL URLWithString:buyCarModel.ImgView]];
    _titleLabel.text = buyCarModel.GoodsTitle;
    _priceLabel.text = [NSString stringWithFormat:@"%.2lf元", buyCarModel.Price];
    _goodsNumLabel.text = [NSString stringWithFormat:@"%ld", (long)buyCarModel.GoodsCount];
    _isSelectButton.selected = buyCarModel.isSelectButton;
}
#pragma mark -
#pragma mark - lazy method
- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:13.0];
        _titleLabel.textColor = [UIColor blackColor];
    }
    return _titleLabel;
}
- (UILabel *)priceLabel
{
    if (!_priceLabel) {
        _priceLabel = [[UILabel alloc] init];
        _priceLabel.font = [UIFont systemFontOfSize:13.0];
        _priceLabel.textColor = [UIColor blackColor];
    }
    return _priceLabel;
}
- (UILabel *)goodsNumLabel
{
    if (!_goodsNumLabel) {
        _goodsNumLabel = [[UILabel alloc] init];
        _goodsNumLabel.textAlignment = NSTextAlignmentCenter;
        _goodsNumLabel.font = [UIFont systemFontOfSize:12.0];
    }
    return _goodsNumLabel;
}
- (UIButton *)isSelectButton
{
    if (!_isSelectButton) {
        _isSelectButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_isSelectButton setImage:[UIImage imageNamed:@"购物车界面商品选中对号按钮"] forState:UIControlStateSelected];
        [_isSelectButton setImage:[UIImage imageNamed:@"购物车界面商品未选中"] forState:UIControlStateNormal];
    }
    return _isSelectButton;
}
- (UIButton *)addButton
{
    if (!_addButton) {
        _addButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _addButton.backgroundColor = [UIColor clearColor];
    }
    return _addButton;
}
- (UIButton *)subButton
{
    if (!_subButton) {
        _subButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _subButton.backgroundColor = [UIColor clearColor];
    }
    return _subButton;
}
- (UIImageView *)iconImageView
{
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc] init];
    }
    return _iconImageView;
}
- (UIImageView *)backImageView
{
    if (!_backImageView) {
        _backImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"购物车界面商品加减按钮"]];
    }
    return _backImageView;
}
- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

@end
